package tech.aistar.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import tech.aistar.entity.User;
import tech.aistar.mapper.UserMapper;
import tech.aistar.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired(required = false)
    private UserMapper userMapper;
    @Override
    public User getByName(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username); // select * from t_user where username = 'ada'
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public List<User> getLikeUser(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.like("username",username);
        List<User> userList =   userMapper.selectList(wrapper);
        return userList;
    }

    @Override
    public Page<User> getByPage(Integer pageNum) {
        //(1)page ： 只封装了页码的信息
        Page<User> page = new Page<>(pageNum,3);// pageNum 要查询的页面, size 每页显示的记录条数
        //(2) pageInfo: 页码信息 + 数据信息
        Page<User> pageInfo =  userMapper.selectPage(page,null);
        System.out.println(pageInfo);
        return pageInfo;
    }
}
